import Layout from "@/layout/Layout.vue";
import Dashboard from "@/views/Dashboard.vue";
import Forward from "@/views/Forward.vue";
import Forwards from "@/views/Forwards.vue";
import Host from "@/views/Host.vue";
import Hosts from "@/views/Hosts.vue";
import Login from "@/views/Login.vue";
import Scripts from "@/views/Scripts.vue";
import Settings from "@/views/Settings.vue";
import Toolbox from "@/views/Toolbox.vue";
import { DashboardFilled } from "@vicons/antd";
import { Network4Reference } from "@vicons/carbon";
import { Toolbox12Filled } from "@vicons/fluent";
import { HardwareChip, Settings as SettingsIcon } from "@vicons/ionicons5";
import { CloudSyncRound, DescriptionFilled } from "@vicons/material";
import type { Component } from "vue";
import { createRouter, createWebHistory } from "vue-router";

declare module "vue-router" {
  interface RouteMeta {
    name: string;
    icon?: Component;
    activeMenu?: string;
    headers?: string[];
  }
}

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  scrollBehavior(to) {
    if (to.hash !== "") {
      document.querySelector(to.hash)?.scrollIntoView();
    }
  },
  routes: [
    {
      path: "/login",
      name: "login",
      component: Login,
    },
    {
      path: "",
      name: "index",
      redirect: "/dashboard",
      component: Layout,
      meta: { name: "OhMyDev", icon: Network4Reference },
      children: [
        {
          path: "/dashboard",
          name: "dashboard",
          component: Dashboard,
          meta: { name: "概览", icon: DashboardFilled },
        },
        {
          path: "/hosts",
          name: "hosts",
          component: Hosts,
          meta: { name: "算力", icon: HardwareChip },
        },
        {
          path: "/host",
          name: "host",
          component: Host,
          meta: {
            name: "编辑",
            activeMenu: "hosts",
            headers: ["index", "hosts", "host"],
          },
        },
        {
          path: "/forwards",
          name: "forwards",
          component: Forwards,
          meta: { name: "转发", icon: CloudSyncRound },
        },
        {
          path: "/forward",
          name: "forward",
          component: Forward,
          meta: {
            name: "编辑",
            activeMenu: "forwards",
            headers: ["index", "forwards", "forward"],
          },
        },
        {
          path: "/scripts",
          name: "scripts",
          component: Scripts,
          meta: { name: "脚本", icon: DescriptionFilled },
        },
        {
          path: "/toolbox",
          name: "toolbox",
          component: Toolbox,
          meta: { name: "工具", icon: Toolbox12Filled },
        },
        {
          path: "/settings",
          name: "settings",
          component: Settings,
          meta: { name: "设置", icon: SettingsIcon },
        },
      ],
    },
  ],
});
export default router;
